package com.itheima.home_work;

import java.util.HashMap;
import java.util.Scanner;

public class Test6 {
    public static void main(String[] args) {
        /**
         * 利用键盘录入，输入一个字符串,统计该字符串中各个字符的数量
         * 如用户输入字符串:"helloworld java",程序输出结果：h(1)e(1)l(3)o(2) (2)w(1)r(1)d(1)j(1)a(2)v(1)
         */

        System.out.println("输入一个字符串,统计该字符串中各个字符的数量：");
        Scanner sc = new Scanner(System.in);

        String info = sc.next();

        HashMap mapCount = new HashMap<Character, Integer>();

        for (int i = 0; i < info.length(); i++) {
            Character key = info.charAt(i);

            if (mapCount.containsKey(key)) {
                Integer count = (Integer) mapCount.get(key);
                mapCount.put(key, count + 1);
            } else {
                mapCount.put(key, 1);
            }
        }

        System.out.println(mapCount);
    }
}
